<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2022/6/14
  Time: 15:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--加入该标签手动开启el功能--%>
<%@page isELIgnored="false" %>
<html>
<head>
    <title>商品管理</title>
    <script type="text/javascript" src="assets/js/jquery.js"></script>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.5/css/layui.css">
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.5/layui.js">
    <link rel="stylesheet" href="css/CommodityManage.css">
</head>
<body>
<form class="layui-form">
    <table class="layui-table">
        <tr>
            <td>商品ID</td>
            <td>商品名称</td>
            <td>商品描述</td>
            <td>商品价格</td>
            <td>商品图片</td>
            <td>商品状态</td>
            <td>操作</td>
        </tr>
        <c:forEach var="od" items="${ogoods}">
            <tr>
                <td id="id">${od.id}</td>
                <td id="goods_name">${od.goods_name}</td>
                <td id="goods_desc">${od.goods_desc}</td>
                <td id="goods_price">${od.goods_price}</td>
                <td id="goods_img"><img src="${od.goods_img}"></td>
                <td id="goods_status">${od.goods_status==1?"正常售卖":"已下架"}</td>
                <td>
                    <a class="layui-btn layui-btn-primary layui-btn-xs open_btn" lay-event="del" title="删除">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</form>

<div class="shade_contents">
    <div class="col-xs-12 shade_colses">
        <button onclick="javascript:onclick_close();">x</button>
    </div>
    <div class="nav shade_content_divs">
        <div class="col-xs-12 shade_title">
            修改商品信息
        </div>
        <div class="col-xs-12 shade_froms">
            <form action="" method="post">
                <div class="col-xs-12">
                    <span class="span_styles">商品编号</span>
                    <span class="span_styles" id="ids"></span>
                </div>
                <div class="col-xs-12">
                    <span class="span_styles">商品名称</span>
                    <input class="input_styles" type="" name="goods_names" id="goods_names" value=""
                           placeholder="请输入商品名称"/>
                </div>
                <div class="col-xs-12">
                    <span class="span_styles"></span>
                    <input class="input_styles" type="" name="goods_descs" id="goods_descs" value=""
                           placeholder="请输入商品描述"/>
                </div>
                <div class="col-xs-12">
                    <span class="span_styles" class="span_sty">商品价格</span>
                    <input class="input_styles" type="" name="goods_prices" id="goods_prices" value=""
                           placeholder="请输入商品价格"/>
                </div>
                <div class="col-xs-12">
                    <span class="span_styles" class="span_sty">商品图片</span>
                    <input class="input_styles" type="" name="goods_imgs" id="goods_imgs" value=""
                           placeholder="请选择商品图片"/>
                </div>
                <div class="col-xs-12">
                    <span class="span_styles" class="span_sty">商品库存</span>
                    <input class="input_styles" type="" name="goods_statuss" id="goods_statuss" value=""
                           placeholder="请输入商品库存"/>
                </div>
                <div class="col-xs-12">
                    <input class="btn_removes" type="button" id="" onclick="javascript:onclick_close();"
                           value="取消"/>
                    <input type="submit" class="sub_sets" id="sub_setID" value="提交"/>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(document).on("click", ".open_btn", function () {
            //获取商品名称
            var username = $(this).parents("tr").find("td:eq(1)").text();
            //获取删除的ID
            var id = $(this).parent().parent().children().eq(0).html();
            alert(id);
            if (confirm("你确定商品【" + username + "】删除吗？")) {
                //根据上面的弹窗判断确认删除发送ajax请求
                $.get("./DeleteGoods", {
                    id: id
                }, function (data) {
                    if (data.trim() === "y") {
                        layer.msg("成功");
                        $("a[title='删除']").parents("tr").children().eq(0).remove();
                        layer.close(index);
                    } else {
                        layer.msg("失败");
                    }
                });
            }
        })

        $(document).on("click", ".open_btns", function () {
            $(".shade_contents").show();
        })
    })

    function onclick_close() {
        var shade_content = $(".shade_contents");
        var shade = $(".shade");
        if (confirm("确认关闭么！此操作不可恢复")) {
            shade_content.hide();
            shade.hide();
        }
    }

    $(".shade_contents").hide();
</script>
</body>
</html>
